﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Medicine.Entity;
using System.Windows.Forms;
using Medicine.Dao;
namespace Medicine.Service
{
    class MedicineServie
    {
        private MedicineDao medicineDao = new MedicineDao();
        /// <summary>
        /// 查询全部药        
       /// </summary>
        public List<Medicin> queryMedAll() {
            String sql = "select * from medicine where ison=1";
            List<Medicin> medicinelist = new List<Medicin>();
            List<Dictionary<String,Object>> ret_list = medicineDao.query(sql);//返回结果集
            foreach (Dictionary<String,Object> dic in ret_list) {
                Medicin medicine = new Medicin();
                medicine.Id = (int)dic["id"];
                medicine.Name = dic["name"].ToString();
                medicine.Information = dic["info"].ToString();
                //MessageBox.Show(dic["price"].ToString());
                medicine.Price = float.Parse(dic["price"].ToString());
                medicine.Ison = (int)dic["ison"];
                medicinelist.Add(medicine);//加入list做返会
            }
            return medicinelist;
        }
        /// <summary>
        /// 查询全部药        
        /// </summary>
        public List<Medicin> queryMedAll1()
        {
            String sql = "select * from medicine";
            List<Medicin> medicinelist = new List<Medicin>();
            List<Dictionary<String, Object>> ret_list = medicineDao.query(sql);//返回结果集
            foreach (Dictionary<String, Object> dic in ret_list)
            {
                Medicin medicine = new Medicin();
                medicine.Id = (int)dic["id"];
                medicine.Name = dic["name"].ToString();
                medicine.Information = dic["info"].ToString();
                //MessageBox.Show(dic["price"].ToString());
                medicine.Price = float.Parse(dic["price"].ToString());
                medicine.Ison = (int)dic["ison"];
                medicinelist.Add(medicine);//加入list做返会
            }
            return medicinelist;
        }
        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="m">删除的数据</param>
        public void delete(Medicin m)
        {
            medicineDao.delete(m);
        }
        /// <summary>
        /// 插入
        /// </summary>
        /// <param name="m">user的实体</param>
        public void insert(Medicin m)
        {
            medicineDao.insert(m);
        }
        /// <summary>
        /// 修改
        /// </summary>
        /// <param name="m">待修改的数据</param>
        public void update(Medicin m)
        {
            medicineDao.update(m);
        }
    }
}
